/*
 * @Descripttion:
 * @version:
 * @Author: ChenXiang
 * @Date: 2021-08-03 19:59:45
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-08-14 12:12:50
 */
import { useState, useRef, useEffect } from "react";
function useSetState(od) {
  const cbRef = useRef(null);
  const [data, setData] = useState(od);

  useEffect(() => {
    cbRef.current && cbRef.current(data);
  }, [data]);

  return [
    data,
    function (d, callback) {
      cbRef.current = callback;
      setData(d);
    },
  ];
}

export default useSetState;
